<?php
class Order_Model_OrderPickup
{

	private $_table;
	//Initalizing Db Table  
	public function __construct(){
		$this->_table = new Order_Model_DbTable_OrderPickup();
	}
	
	/**
	*Create A Record  
	*@param rowSet $row warehouse's data 
	*@return boolean
	*/
	public  function add($row){	 
 		return $this->_table->insert($row); 
	}
	
	public  function update($row,$id){
		$where = $this->_table->getAdapter()->quoteInto('op_id = ?', $id);
		return $this->_table->update($row, $where);	
	}
	
	public function updateByField($row,$field,$value)
	{ 
		$where = $this->_table->getAdapter()->quoteInto("{$field}= ?", $value);
		return $this->_table->update($row, $where);
	}
	
	public function getByValue($value,$field){
        $select = $this->_table->getAdapter()->select();
        $table  = $this->_table->info('name');
        $select->from($table,'*');
        $select->where("{$field} = ?",$value);
		return $this->_table->getAdapter()->fetchRow($select);
	}

	
	public function getByCond($condition=array(),$type='*',$pageSize=0,$page=1,$orderby=array())
	{
        $select = $this->_table->getAdapter()->select();
        $table = $this->_table->info('name');
        $select->from($table,$type);
        $select->where("1 =?",1);
        if(isset($condition['op_id']) && $condition['op_id']!=''){
            $select->where('op_id=?', $condition['op_id']);
        }
		if(isset($condition['op_code']) && $condition['op_code']!=''){
            $select->where('op_code=?', $condition['op_code']);
        }
        if(isset($condition['op_status']) && $condition['op_status'] !==''){
            $select->where('op_status=?', $condition['op_status']);
        }
        if('count(*)'==$type){
            return $this->_table->getAdapter()->fetchOne($select);
        }else{
            $select->order($orderby);
            if($pageSize>0 and $page>0){
                $start =($page-1)*$pageSize;
                $select->limit($pageSize,$start);
            }
			$sql=$select->__toString();
		    return $this->_table->getAdapter()->fetchAll($sql);
        }
	}
	

	
}